package ma30082014;

import java.util.HashSet;
/*
 Googly sum
 Max. Score 100
 In this problem of Googly sum nikki gives you a sequence A consisting of N integers. 
 nikki will call the ith sequence element good if it equals to the sum of some three elements in positions strictly smaller than i . 
 Now nikki asks you a simple question how many good elements does the sequence contain?

 Note : An element can be used more than once in the sum i.e lets say sequence is [1 3 5 9] (indexing from 0) 
 consider the following points -

 1) In sequence 1 is not good obviously.

 2) 3 is good as 1 can be added three times to get 3

 3) 5 is good as adding two times 1 and one time 3 will give 5

 4) 9 is good as 1+3+5=9 and also adding element 3 three times will give 9 so any of these condition can be used to count 9 as good.

 Input :

 The first line of input contains the positive integer N , the length of the sequence A. 
 The second line of input contains N space-separated integers representing the sequence A .

 Output :

 The first and only line of output must contain the number of good elements in the sequence.

 Constraints :

 1 <= N <= 5000

 -10^5 <= Ai <= 10^5

 Sample Input (Plaintext Link)
 6
 1 2 3 5 7 10

 Sample Output (Plaintext Link)
 4
 */
import java.util.Scanner;

public class Solution2 {

	static int n;
	static int[] A;

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		n = s.nextInt();
		A = new int[n];
		int nGood = 0;
		// b+c
		HashSet<Integer> knownSummedSet = new HashSet<Integer>();

		for (int i = 0; i < n; ++i) {
			A[i] = s.nextInt();
			for (int j = 0; j < i; ++j) {
				// a
				if (knownSummedSet.contains(A[i] - A[j])) {
					++nGood;
					break;
				}
			}
			// b+c
			for (int j = 0; j <= i; ++j) {
				knownSummedSet.add(A[j] + A[i]);
			}
		}
		System.out.println(nGood);
		s.close();
	}

}
